package com.twu.biblioteca;

import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by elimydlarz on 18/04/14.
 */
public class UserManager {

    private final HashMap<String, User> users;
    private User activeUser;

    public UserManager() {
        users = new HashMap<String, User>();
        activeUser = null;
    }

    public UserManager(HashMap<String, User> users, User activeUser) {
        this.users = users;
        this.activeUser = activeUser;
    }

    public Boolean userIsLoggedIn() {
        if (activeUser != null) return true;
        else return false;
    }

    public User getActiveUser() {
        return activeUser;
    }

    public Boolean attemptLogIn(String userKeyEntered, String passwordEntered) {
        User foundUser = users.get(userKeyEntered);
        if (foundUser != null) {
            if (foundUser.checkPassword(passwordEntered)) {
                activeUser = foundUser;
                return true;
            }
        }
        return false;
    }

    public Boolean attemptLogOut() {
        if (activeUser != null) {
            activeUser = null;
            return true;
        }
        else {
            return false;
        }
    }
}
